<head>

<script>

	[Metadata1]
	[Metadata2]
	[MetadataType]
	
	var URI="[URL]"; 

 	function convertSpaces(s){
		var index=s.indexOf(" && ");
		while (index!=-1){
			s = s.substring(0,index)+"^"+s.substring(index+4);
			index=s.indexOf(" && ");
		}	 
				index=s.indexOf("\\\"");
		while (index!=-1){
			s = s.substring(0,index)+"~"+s.substring(index+2);
			index=s.indexOf("\\\"");
		}
		for(var i=0; i<s.length; i++){
			if(s.charAt(i) == ' ')
				s = s.substring(0,i)+"+"+s.substring(i+1);
		}
		return s;
	}
	
	function metadataQuery(value,i){
		if (metadataType[i]=="string"){
			return "<a href=\""+URI+"/search?page=0&"+
				"query"+"="
				+convertSpaces(metadata[i]+":~"+value+"~")+
				">"+metadata2[i]+": "+value+"</a><br /><br />";
		}
		if (metadataType[i]=="date"){
			var split=value.split(" ");
			var year=split[split.length-1];
		
			return "<a href=\""+URI+"/search?page=0&"+"query"+"="
					+convertSpaces(metadata[i]+":["+year+"-01-01T00:00:00.000Z TO "+year+"-12-31T23:59:59.999Z]")+
					">"+metadata2[i]+" year: "+year+"</a><br /><br />";
		}
		
		if (metadataType[i]=="array"){
			if (value[0]=='['){
				value=value.substring(1);
			}
			if (value[value.length-1]==']'){
				value=value.substring(0,value.length-1);
			}
			var values=value.split(", ");
			var ans=metadata2[i]+": ";
			for(var j=0;j<values.length;j++){
				ans+="<br /><a href=\""+URI+"/search?page=0&query="+
				convertSpaces(metadata[i]+":~"+values[j])+"~\">"+values[j]+"</a>, ";
				
			}//end for
			return ans.substring(0,ans.length-2)+"<br /><br />";
		}
		return "";		
	}	
	
	
	function showMetadata(articlesArray){
		var ans="";
		for(var i=0; i<metadata.length;i++){
			ans+=metadata2[i]+": "+articlesArray.getElementsByTagName(metadata[i])[0].childNodes[0].nodeValue+" <br />";
		}
		return ans+"<br />";
	}

	function showTopics(articlesArray,newLine){
		var ans="Topics: ";
		var allTopicsId=articlesArray.getElementsByTagName("topicsID")[0].childNodes[0].nodeValue;	
			
		if (allTopicsId.length==0)
			return "No topics <br />";		
			
		allTopicsId=allTopicsId.split(",");

		var allTopicsName=articlesArray.getElementsByTagName("topicsName")[0].childNodes[0].nodeValue;
		
		
		//allTopicsName=allTopicsName.split(",");
		allTopicsName=allTopicsName.split("],[");
		
		allTopicsName[0]+=", ";
		allTopicsName[0]+="]";
		allTopicsName[allTopicsName.length-1]="["+allTopicsName[allTopicsName.length-1];
		
		for(var i=1;i<allTopicsName.length-1;i++)
			//allTopicsName[i]=allTopicsName[i]+", ";
			allTopicsName[i]="["+allTopicsName[i]+"]";
		
		for(var i=0 ; i<allTopicsId.length ; i++){
			if (newLine)
				ans+="<br />";
			ans+="<a href=\""+URI+"/search?query=*:*&page=0&topic="+allTopicsId[i]+"\">"+
				allTopicsName[i]+"</a>"+((i<allTopicsId.length-1)?", ":"");		
		}
		return ans+"<br />";
	}
	
	function showMoreArticles(articlesArray){
		var moreArticlesDiv=document.getElementById("moreArticles");
		moreArticlesDiv.innerHTML+="See more Articles:<br />";
		var metadata1Values=new Array(metadata.length);
		
		for(var i=0;i<metadata1Values.length;i++){
			metadata1Values[i]=articlesArray[0].getElementsByTagName(metadata[i])[0].childNodes[0].nodeValue;
		}

		for(var i=0;i<metadata.length;i++){
			moreArticlesDiv.innerHTML+=metadataQuery(metadata1Values[i],i);
		}
		
		moreArticlesDiv.innerHTML+=showTopics(articlesArray[0],true);
	}

	function replaceAll(text,from,to1){
		var splited=text.split(from);
		var ans=splited[0];
		for(var i=1;i<splited.length;i++)
			ans+=to1+splited[i];
		return ans;
	}

	function showArticle(xmlDoc){
	
		var articlesArray = xmlDoc.getElementsByTagName("aritcle");		
		var articlesDiv=document.getElementById("articlesMain");
		
		articlesDiv.innerHTML+="<b>"+
			articlesArray[0].getElementsByTagName("title")[0].childNodes[0].nodeValue+
			"</b><br /><br />"+ 
			showMetadata(articlesArray[0]) +showTopics(articlesArray[0],false)+"<br />"+
			//articlesArray[0].getElementsByTagName("text")[0].childNodes[0].nodeValue+
			replaceAll(articlesArray[0].getElementsByTagName("text")[0].childNodes[0].nodeValue,"\n","<br />")+
			"<br />";
		
		showMoreArticles(articlesArray);
	}

	onload = function(){ 	
		
		var xmlHttp = new XMLHttpRequest();
		xmlHttp.open("GET", URI+"/article2?id=[ArticleId]", true);
		xmlHttp.setRequestHeader("Content-Type", "text/xml");
		
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				showArticle(xmlHttp.responseXML)
			}
		};
		xmlHttp.send();
	};
	
</script>

	
<title>Learning Content Models for Semantic Search Project</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
h01 {
	display: block;
	background-color: #B9C9FE;
	letter-spacing: 0.3em;
	color: #0033BC;
	text-align: center;
}

h02 {
	display: block;
	background-color: #E8EDFF;
	letter-spacing: 0.3em;
	color: #666699;
	text-align: center;
}

</style>
</head>

<body>

<h01>Learning Content Models for Semantic Search</h01>
<hr />
<h02>Results</h02>

<div id="moreLinks" style="position: absolute; top: 80px; left: 20px;">

<br />
</div>

<div id="articlesMain" style="position: absolute; top: 80px; left: 300px;">

</div>

<div id="moreArticles" style="position: absolute; top: 120px; left: 20px; width:250px;">

<br />
</div>

</body>
</html>
